package vashion.azeroth.core.oss;

import java.math.BigDecimal;
import java.text.DecimalFormat;

/**
 * Created by liuhe on 15/9/16.
 */
public class MoneyUtil {

    /**
     * 分转元
     *
     * @param fen
     * @return
     */
    public static String fenToYuan(long fen) {
        if (fen <= 0) {
            return "0.00";
        }
        Double yuan = fen / 100d;
        DecimalFormat df = new DecimalFormat("###0.00");
        return df.format(yuan);
    }

    /**
     * 分转元
     *
     * @param fen
     * @return
     */
    public static Double fenToYuanDouble(long fen) {
        if (fen <= 0) {
            return 0d;
        }
        return fen / 100d;
    }

    public static long yuanToCent(String yuan) {
        BigDecimal decimal = new BigDecimal(yuan);
        decimal = decimal.movePointRight(2);
        return decimal.longValue();
    }

    public static long yuanToCent(Double yuan) {
        BigDecimal decimal = new BigDecimal(yuan);
        decimal = decimal.movePointRight(2);
        return decimal.longValue();
    }
}
